﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MapLibrary.GUI;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace GUILibrary
{
    public class RepeatDrawComponent : Component
    {

        public string TextureName
        {
            get;
            set;
        }

        public int HorizontalPadding
        {
            get;
            set;
        }

        [ContentSerializerIgnore]
        public ITrackable ToTrack
        {
            get { return ToTrack; }
            set
            {
                toTrack = value;
                CheckAndTriggerInitialized();
            }
        }

        private ITrackable toTrack;
        private Texture2D toDraw;

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch batch)
        {
            if (!Initialized)
                return;

            Vector2 currPos = ScreenPosition;
            for (int i = 0; i < toTrack.GetAmount(Name); i++)
            {
                batch.Draw(toDraw, currPos, Color.White);
                currPos += new Vector2(HorizontalPadding + toDraw.Bounds.Width, 0);
            }
        }

        public override void Load(Microsoft.Xna.Framework.Content.ContentManager cm)
        {
            toDraw = cm.Load<Texture2D>(TextureName);
        }

        public void CheckAndTriggerInitialized()
        {
            if (toTrack != null)
                Initialized = true;
        }
    }
}
